package com.zxl.security.core.social.weixin.config;

import com.zxl.security.core.social.properties.SecurityProperties;
import com.zxl.security.core.social.properties.WeiXinProperties;
import com.zxl.security.core.social.weixin.connect.WeiXinConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Configuration;
import org.springframework.social.connect.ConnectionFactory;

@Configuration
@ConditionalOnProperty(prefix = "zxl.security.social.weiXin", name = "appId")
public class WeiXinAutoConfig extends SocialAutoConfigurerAdapter {

    @Autowired
    private SecurityProperties securityProperties;

    @Override
    protected ConnectionFactory<?> createConnectionFactory() {
        WeiXinProperties properties = securityProperties.getSocial().getWeiXin();
        return new WeiXinConnectionFactory(properties.getProviderId(), properties.getAppId(), properties.getAppSecret());
    }
}
